aed60f17f70f7982a6a6f5ec3c4531179492eca9,src/test/java/com/n1analytics/paillier/FuzzTest.java,FuzzTest,fuzzDoubleMixOperations4,#,188

Before Change



    for(int i = 0; i < maxIteration; i++) {
      a = randomFiniteDouble();
      b = randomFiniteDouble();
      c = randomFiniteDouble();
      d = randomFiniteDouble();

      // Check if the numbers are "close enough"
      double minVal = a - (a * EPSILON), maxVal = a + (a * EPSILON);
      if((b > maxVal || b < minVal) && (c > maxVal || c < minVal))
        continue;

      if(Double.isInfinite(1 / d) || Double.isNaN(1/d)) {
        continue;
      }

      plainResult = (a + (b * c)) / d;

      if(context.isUnsigned() && (a < 0 || b < 0 || c < 0 || d < 0 || plainResult < 0)) {
        continue;
      }

      ciphertextA = context.encrypt(a);
      ciphertextB = context.encrypt(b);
      encodedC = context.encode(c);

      encryptedResult = ciphertextA.add(ciphertextB.multiply(encodedC)).divide(d);

After Change



    for(int i = 0; i < maxIteration; i++) {
      a = randomFiniteDouble();
      double maxDist = a * EPSILON;
      b = a + (rnd.nextDouble() - 0.5) * 2 * maxDist;
      c = (rnd.nextDouble() - 0.5) * 100; //has to be small to prevent overflows
      d = a + (rnd.nextDouble() - 0.5) * 2 * maxDist;

      if (context.isUnsigned()) {
        if (a < 0) {
          a = -a;
        }
        if (b < 0) {
          b = -b;
        }
        if (c < 0) {
          c = -c;
        }
        if (d < 0) {
          d = -d;
        }
      }

      if(Double.isInfinite(1 / d) || Double.isNaN(1/d)) {
        continue;
      }

      plainResult = (a + (b * c)) / d;

      ciphertextA = context.encrypt(a).obfuscate();
      ciphertextB = context.encrypt(b).obfuscate();
      encodedC = context.encode(c);

      encryptedResult = ciphertextA.add(ciphertextB.multiply(encodedC)).divide(d);